﻿<!DOCTYPE html>
<!--岗位安全职责考核管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="/static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="/static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .widthZ .el-input__inner {
            width: 0px !important;
        }
        /*.widthZ .el-input-group__prepend {
            width: 150px !important;
        }*/

        .widthZ .el-select {
            width: 100% !important;
        }

        .widthZ .el-input-group__append {
            width: 100% !important;
        }

        .widthZ .el-select .el-input__inner {
            width: 100% !important;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW150">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini"
                 label-position="right">
            <el-row>
                <el-col :span="11">
                    <p class="main-label">考核年份</p>
                    <p class="lh35">{{Form.assessmentYear}}</p>
                </el-col>
                <el-col :span="11" :offset="2">
                    <p class="main-label">岗位人员</p>
                    <p class="lh35">{{Form.mark04}}</p>
                </el-col>

            </el-row>
            <el-row>
                <el-col :span="11">
                    <p class="main-label">岗位名称</p>
                    <p class="lh35">{{Form.mark01}}</p>
                </el-col>
                <el-col :span="11" :offset="2">
                    <p class="main-label">部门</p>
                    <p class="lh35">{{Form.mark03}}</p>
                </el-col>

            </el-row>
            <el-row>
                <el-col :span="24">
                    <p class="main-label">岗位安全生产责任范围</p>
                    <p class="lh35">{{Form.postSafeProductionScope}}</p>
                </el-col>


            </el-row>
            <!--<el-row>
        <el-col :span="11">
            <div class="elst-select-mini">
                <el-form-item>
                    <el-input size="mini">
                        <template slot="prepend">
                            {{'选择人员'+mark.m}}
                        </template>
                        <treeselect v-model="Form.postPerson" :options="users" :flat="true"
                                    :disable-branch-nodes="true" slot="suffix" placeholder="请选择"
                                    style="line-height: 28px;" />
                    </el-input>
                </el-form-item>
            </div>
        </el-col>
        <el-col :span="11" offset="2">
            <div class="elst-select-mini elst-select-minis">
                <el-form-item>
                    <el-input class="input-with-select widthZ" size="mini">
                        <template slot="prepend">
                            {{PostSafeResponsibilityExamineManager.task+mark.m}}
                        </template>
                        <el-select @visible-change="visibleChange" v-model="Form.jobsAssessTask" slot="append"   placeholder="请选择" @change="taskChange">
                            <el-option label="请选择" value=""></el-option>
                            <el-option v-for="item in tasks" :label="item.theme" :value="item.id"></el-option>
                        </el-select>
                    </el-input>
                </el-form-item>
            </div>

        </el-col>
        <el-col :span="11" offset="2">
            <div class="elst-select-mini">
                <el-form-item>
                    <el-input size="mini">
                        <template slot="prepend">
                            {{PostSafeResponsibilityExamineManager.year+mark.m}}
                        </template>
                        <el-date-picker v-model="Form.assessmentYear" type="year" slot="suffix" format="yyyy"
                                        value-format="yyyy" size="mini" placeholder="选择日期">
                        </el-date-picker>
                    </el-input>
                </el-form-item>
            </div>
        </el-col>
    </el-row>-->
            <!--<el-row>
        <el-col :span="11">
            <div class="elst-select-mini">
                <el-form-item>
                    <el-input size="mini">
                        <template slot="prepend">
                            {{'选择部门'+mark.m}}
                        </template>
                        <treeselect v-model="departmentId" :options="department" :flat="true"
                                    slot="suffix" placeholder="请选择"
                                    style="line-height: 28px;" />
                    </el-input>
                </el-form-item>
            </div>
        </el-col>
        <el-col :span="11" offset="2">
            <div class="elst-select-mini elst-select-minis">
                <el-form-item>
                    <el-input class="input-with-select widthZ" size="mini">
                        <template slot="prepend">
                            {{PostSafeResponsibilityExamineManager.post+mark.m}}
                        </template>
                        <el-select @visible-change="visibleChange" v-model="dutyId" slot="append" placeholder="请选择"  @change="postChange">
                            <el-option label="请选择" value=""></el-option>
                            <el-option v-for="item in duties" :label="item.sysDuty.name" :value="item.sysDuty.id"></el-option>
                        </el-select>
                    </el-input>
                </el-form-item>
            </div>

        </el-col>
    </el-row>-->
            <!--<el-row>
        <el-col :span="11">
            <div class="elst-select-mini">
                <el-form-item>
                    <el-input type="text" v-model="Form.theme" autocomplete="off" size="mini">
                        <template slot="prepend">
                            {{PostSafeResponsibilityExamineManager.assessmentSubject+mark.m}}
                        </template>
                    </el-input>
                </el-form-item>
            </div>
        </el-col>
        <el-col :span="11" offset="2">

        </el-col>
    </el-row>

    <el-row>
        <el-col :span="24">
            <div class="elst-select-mini">
                <el-form-item>
                    <div class="el-input--mini el-input-group">
                        <div class="el-input-group__prepend">
                            {{PostSafeResponsibilityExamineManager.postSafeProductionScope+mark.m}}
                        </div>
                        <el-input class="el-textarea__inner" type="textarea" v-model="Form.postSafeProductionScope"
                                  autocomplete="off"></el-input>
                    </div>
                </el-form-item>
            </div>
        </el-col>

    </el-row>-->
            <el-table ref="table" v-if="showTable" :data="Form.jG_JobsAssessDetail" :row-key="getRowKeys" border
                      @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%;">
                <el-table-column type="index" :label="PostSafeResponsibilityExamineManager.id" :index="indexMethod"
                                 width="60" show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="postSafeProductionContent"
                                 :label="PostSafeResponsibilityExamineManager.postSafeProductionContent" show-overflow-tooltip="true"
                                 width="300">
                </el-table-column>
                <el-table-column prop="assessmentContent"
                                 :label="PostSafeResponsibilityExamineManager.assessmentContent" show-overflow-tooltip="true"
                                 width="100">
                </el-table-column>
                <el-table-column prop="weightScore" :label="PostSafeResponsibilityExamineManager.weight"
                                 show-overflow-tooltip="true" width="100">
                </el-table-column>
                <el-table-column prop="effectAndDescription"
                                 :label="PostSafeResponsibilityExamineManager.effectAndDescription" show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="score" :label="PostSafeResponsibilityExamineManager.score"
                                 show-overflow-tooltip="true" width="100">
                </el-table-column>
                <!--<el-table-column prop="effectAndDescription"
                         :label="PostSafeResponsibilityExamineManager.effectAndDescription" show-overflow-tooltip="true">
            <template slot-scope="scope">
                <el-input v-model="scope.row.effectAndDescription" size="mini"
                          placeholder="工作效果和评估描述" class="weightScore">
                </el-input>
            </template>
        </el-table-column>
        <el-table-column prop="score" :label="PostSafeResponsibilityExamineManager.score"
                         show-overflow-tooltip="true" width="100">
            <template slot-scope="scope">
                <el-input v-model="scope.row.score" size="mini"
                          placeholder="评分" class="weightScore"></el-input>
            </template>
        </el-table-column>-->
            </el-table>


            <el-row  style="margin-top:20px;">
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{"退回原因"+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.backResult"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>


            <el-row type="flex" justify="end" style="margin-top:20px;">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm','2')">{{"通过"}}</el-button>
                    <el-button type="primary" @click="onSubmitForm('ruleForm','0')">{{"退回"}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                mydata: [],// UsersTree,
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    //postPerson:'',
                    jobsAssessTask: '',
                    mark04: '',
                    mark01: '',
                    mark03: '',
                    postID: '',
                    postNameID: '',
                    theme: '',
                    //assessmentSubject:'',
                    assessmentYear: '',
                    postSafeProductionScope: '',
                    status: '0',
                    jG_JobsAssessDetail: [],
                    backResult:''//退回原因
                    //tableData:[],
                },
                ////部门数据集
                //department: [],
                ////职务数据集
                //duties: [],
                //部门model
                departmentId: null,
                //职务model
                dutyId: null,
                ////选择部门后的信息对象
                //deparmentObject: null,
                ////岗位集合
                //post: [],
                //人员集合
                users: [],
                //任务集合
                tasks: [],
                //表格显示开关
                showTable: true,
                //表单验证
                rules: {
                    //jobsAssessTask: [
                    //    verification.NotNull,
                    //],

                    //postPerson: [
                    //    verification.NotNull,
                    //]

                }
            },
            //watch: {
            //    //下拉树监控
            //    departmentId(val, oldval) {
            //        //初始化职务选项
            //        if (this.id == null) {
            //            this.dutyId = null;
            //        }
            //        //获取部门信息（含中间表及职务数据）
            //        this.getDuty(val);
            //        //绑定职务下拉框
            //        this.duties = this.deparmentObject.sysDepartmentDuties;
            //    }
            //},
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //表格序号连续化
                indexMethod: function (index) { return index + 1; },
                //提交数据
                //onSubmitForm: function (formName) {
                //    var mythis = this;
                //    this.$refs[formName].validate(function (valid) {
                //        //验证通过
                //        if (valid) {
                //            mythis.Form.status = status;
                //            mythis.Form.postID = mythis.departmentId;
                //            mythis.Form.postNameID = mythis.dutyId;
                //            //mythis.Form.theme = mythis.Form.assessmentSubject
                //            //mythis.Form.jG_JobsAssessDetail = mythis.Form.tableData
                //            onSubmitForm(this, '/api/JG_JobsAssess/Save', mythis.Form);
                //        } else {
                //            //验证失败
                //            return false;
                //        }
                //    });

                //},
                onSubmitForm: function (formName, status) {
                    var mythis = this;
                    mythis.Form.assessmentYear = mythis.Form.assessmentYear.toString().substring(0,4)+"-01-01 00:00:00.000";
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            if (mythis.id != null) {
                                if (status == "0" && mythis.Form.backResult == "") {
                                    alert('请输入退回原因');
                                    return;
                                } else {

                                    mythis.Form.status = status;
                                    mythis.Form.postID = mythis.departmentId;
                                    mythis.Form.postNameID = mythis.dutyId;
                                    //mythis.Form.theme = mythis.Form.assessmentSubject;
                                    mythis.Form.jG_JobsAssessDetail = mythis.Form.tableData
                                    var tempScore = 0;
                                    for (var j = 0; j < mythis.Form.jG_JobsAssessDetail.length; j++) {
                                        var weightScore = mythis.Form.jG_JobsAssessDetail[j].weightScore;
                                        var score = mythis.Form.jG_JobsAssessDetail[j].score;
                                        if (score == null || score == "" || score == undefined || parseFloat(score) < 0 || parseFloat(score) > parseFloat(weightScore)) {
                                            if (parseFloat(score) == 0) { } else {
                                                alert('评分必须大于等于0并且小于权重分');
                                                return;
                                            }
                                        } else {
                                            tempScore = parseFloat(tempScore) + parseFloat(score);
                                        }
                                    }
                                    mythis.Form.mark04 = tempScore;
                                    //mythis.Form.jG_JobsAssessDetail = mythis.Form.tableData
                                    onSubmitForm(this, '/api/JG_JobsAssess/Save2', mythis.Form);
                                }

                            } else {
                                alert('当前考核不存在');
                                return;
                                //当前考核是否存在
                                ////myAjax("post", this, '/api/JG_JobsAssess/getModel', { model: { assessmentYear: mythis.Form.assessmentYear, postPerson: mythis.Form.postPerson, postID: mythis.departmentId, postNameID: mythis.dutyId }, offset: 0, limit: 10 }, function (response) {
                                //myAjax("post", this, '/api/JG_JobsAssess/getModel', { model: { jobsAssessTask: mythis.Form.jobsAssessTask, postPerson: mythis.Form.postPerson, postID: mythis.departmentId }, offset: 0, limit: 10 }, function (response) {
                                //    if (response.data.pageData.length == 0) {
                                //        mythis.Form.status = status;
                                //        mythis.Form.postID = mythis.departmentId;
                                //        mythis.Form.postNameID = mythis.dutyId;
                                //        //mythis.Form.theme = mythis.Form.assessmentSubject
                                //        //mythis.Form.jG_JobsAssessDetail = mythis.Form.tableData
                                //        var tempScore = 0;
                                //        for (var j = 0; j < mythis.Form.jG_JobsAssessDetail.length; j++) {
                                //            var weightScore = mythis.Form.jG_JobsAssessDetail[j].weightScore;
                                //            var score = mythis.Form.jG_JobsAssessDetail[j].score;
                                //            if (score == null || score == "" || score == undefined || parseFloat(score) < 0 || parseFloat(score) > parseFloat(weightScore)) {
                                //                if (parseFloat(score) == 0) { } else {
                                //                    alert('评分必须大于等于0并且小于权重分');
                                //                    return;
                                //                }
                                //            } else {
                                //                tempScore = parseFloat(tempScore) + parseFloat(score);
                                //            }
                                //        }
                                //        mythis.Form.mark04 = tempScore;
                                //        //mythis.Form.jG_JobsAssessDetail = mythis.Form.tableData
                                //        onSubmitForm(this, '/api/JG_JobsAssess/Save2', mythis.Form);

                                //    } else {
                                //        alert('已考核,请换其他人');
                                //        return false;
                                //    }
                                //}, false);
                            }
                        } else {
                            //验证失败
                            return false;
                        }
                    });

                },
                getData: function () {
                    var mythis = this;
                    if (mythis.id != null && mythis.id != '') {
                        myAjax("get", mythis, '/api/JG_JobsAssess/get?id=' + this.id, null, function (response) {
                            var ajaxModel = response.data;
                            mythis.Form = ajaxModel;
                            mythis.departmentId = ajaxModel.postID;
                            mythis.dutyId = ajaxModel.postNameID;
                            //mythis.Form.assessmentSubject = ajaxModel.theme;
                            //mythis.Form.postNameID = ajaxModel.postNameID;
                            //mythis.Form.assessmentYear = ajaxModel.assessmentYear;//mythis.Form.assessmentYear.toString().substring(0, 4);
                            //mythis.userFrom.sex = mythis.userFrom.sex + "";
                            mythis.Form.assessmentYear = ajaxModel.jG_JobsAssessTask.assessmentYear.toString().substring(0, 4);
                            mythis.Form.theme = ajaxModel.jG_JobsAssessTask.theme;
                            mythis.Form.postSafeProductionScope = ajaxModel.jG_JobsAssessTask.postSafeProductionScope;
                            mythis.Form.mark04 = ajaxModel.sysUser.name;

                            myAjax("post", this, '/api/JG_JobsAssessTask/GetList', { model: { assessmentYear: ajaxModel.jG_JobsAssessTask.assessmentYear, postNameID: ajaxModel.jG_JobsAssessTask.postNameID, postID: ajaxModel.jG_JobsAssessTask.postID, theme: ajaxModel.jG_JobsAssessTask.theme }, offset: 0, limit: 100 }, function (response) {

                                if (response.data == null || response.data.length == 0) {
                                    mythis.tasks = []
                                } else {
                                    var mt = response.data.pageData[0];
                                    mythis.Form.mark01 = mt.mark01;//岗位
                                    mythis.Form.mark03 = mt.mark02;//部门
                                }
                            }, false);

                            mythis.Form.tableData = ajaxModel.jG_JobsAssessDetail;
                        }, false);
                    }
                },
                postChange: function (val) {

                    var mythis = this;
                    if (mythis.id != null) {
                        myAjax("post", this, '/api/JG_JobsAssessTemplate/get', { model: { postID: val }, offset: 0, limit: 10 }, function (response) {
                            if (response.data.pageData.length == 0) {
                                mythis.Form.jG_JobsAssessDetail = [];

                            } else {
                                //mythis.Form.id = response.data.pageData[0].id;
                                mythis.Form.theme = mythis.Form.assessmentYear + '年' + response.data.pageData[0].postSafeProductionContent + '岗位考核';

                                if (val) this.showTable = true
                                else this.showTable = false
                            }
                        }, false);

                    } else {
                        var tableData = [];
                        myAjax("post", this, '/api/JG_JobsAssessTemplate/get', { model: { postID: val }, offset: 0, limit: 10 }, function (response) {
                            if (response.data.pageData.length == 0) {
                                mythis.Form.jG_JobsAssessDetail = [];

                            } else {
                                //mythis.Form.id = response.data.pageData[0].id;
                                mythis.Form.theme = mythis.Form.assessmentYear + '年' + response.data.pageData[0].postSafeProductionContent + '岗位考核';
                                var list = response.data.pageData[0].jG_JobsAssessTemplateDetail
                                for (var j = 0; j < list.length; j++) {
                                    tableData.push({
                                        postSafeProductionContent: list[j].postSafeProductionContent,//岗位安全生产责任内容
                                        assessmentContent: list[j].assessmentContent,//考核内容
                                        weightScore: list[j].weightScore,//权重分
                                        effectAndDescription: '',//评估描述
                                        score: 0,//评分
                                    })
                                }
                                mythis.Form.jG_JobsAssessDetail = tableData;

                                if (val) this.showTable = true
                                else this.showTable = false
                            }
                        }, false);
                    }


                }
                , getDepartmentUserData: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/JG_JobsAssess/GetDepartmentUserList', { model: {}, offset: 0, limit: 99999 }, function (response) {

                        if (response.data == null || response.data.length == 0) {
                            mythis.users = []
                        } else {
                            mythis.users = menuHelper(response.data, guidEmpty)
                        }
                    }, false);

                },
                taskChange: function (val) {

                    var mythis = this;
                    myAjax("get", mythis, '/api/JG_JobsAssessTask/get?id=' + val, null, function (response) {
                        var ajaxModel = response.data;
                        //mythis.Form = ajaxModel;
                        mythis.departmentId = ajaxModel.createDept;
                        mythis.dutyId = ajaxModel.postNameID;
                        //mythis.Form.postNameID = ajaxModel.postNameID;
                        //mythis.Form.assessmentYear = mythis.Form.assessmentYear.toString().substring(0, 4);
                        mythis.Form.assessmentYear = ajaxModel.assessmentYear;
                        mythis.Form.theme = ajaxModel.theme;
                        mythis.Form.postSafeProductionScope = ajaxModel.postSafeProductionScope;
                        mythis.Form.jobsAssessTask = val;

                        var tableData = [];
                        myAjax("post", this, '/api/JG_JobsAssessTemplate/get', { model: { postID: ajaxModel.postNameID }, offset: 0, limit: 100 }, function (response) {
                            if (response.data.pageData.length == 0) {
                                mythis.Form.jG_JobsAssessDetail = [];

                            } else {

                                //mythis.Form.theme = mythis.Form.assessmentYear + '年' + response.data.pageData[0].postSafeProductionContent + '岗位考核';
                                var list = response.data.pageData[0].jG_JobsAssessTemplateDetail
                                for (var j = 0; j < list.length; j++) {
                                    tableData.push({
                                        postSafeProductionContent: list[j].postSafeProductionContent,//岗位安全生产责任内容
                                        assessmentContent: list[j].assessmentContent,//考核内容
                                        weightScore: list[j].weightScore,//权重分
                                        effectAndDescription: '',//评估描述
                                        score: 0,//评分
                                    })
                                }
                                mythis.Form.jG_JobsAssessDetail = tableData;

                                if (val) this.showTable = true
                                else this.showTable = false
                            }
                        }, false);

                    }, false);
                },
                getJobsAssessTaskData: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/JG_JobsAssessTask/GetList', { model: { state: '1' }, offset: 0, limit: 100 }, function (response) {

                        if (response.data == null || response.data.length == 0) {
                            mythis.tasks = []
                        } else {
                            mythis.tasks = menuHelper(response.data.pageData, guidEmpty)
                        }
                    }, false);

                },
                ////初始化部门下拉树(完成)
                //getDepartmentData: function () {
                //    var mythis = this;
                //    myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: null }, offset: 0, limit: 10 }, function (response) {
                //        mythis.department = menuHelper(response.data.pageData, guidEmpty);
                //        mythis.Form.jG_JobsAssessDetail = [];
                //    }, false);

                //},
                ////联动职务下拉框(完成)
                //getDuty: function (pid) {
                //    var mythis = this;
                //    myAjax("get", mythis, '/api/SysDepartment/Get?id=' + pid, null, function (response) {
                //        console.log(' response.data', response.data)
                //        mythis.deparmentObject = response.data;

                //    }, false);
                //},
            },
            mounted: function () {
                ////初始化部门下拉树数据
                //this.getDepartmentData();
                //this.getDepartmentUserData();
                //this.getJobsAssessTaskData();
                //this.post = getDicData('postname');
                //this.users = fn(this.mydata, "0");
                this.id = getUrlParam("id");
                this.getData();
                if (this.Form.post) {
                    this.showTable = true;
                }
                console.log('this.Form', this.Form)
            }
        });
        //下拉树数据格式化
        function menuHelper(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelper(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>